﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using HomeBuyerTools.ViewModels;
using HomeBuyerTools.FinanceProperties;

namespace HomeBuyerTools.Views
{
    public partial class Estmatedsalesprice : PhoneApplicationPage
    {
        public Estmatedsalesprice()
        {
            InitializeComponent();
            Loaded += Estmatedsalesprice_Loaded;
            REg.Value = DateTime.Now;
            if (Appsettings.RegstrationDate != "")
            {
                REg.Value = Convert.ToDateTime(Appsettings.RegstrationDate);
            }
        }

        void Estmatedsalesprice_Loaded(object sender, RoutedEventArgs e)
        {
            LoadPivotThemes();
            txtCommission.Text = Appsettings.AgentCommission.ToString();
            txtTotalPrice.Text = App.TotalPrice.ToString();
            double CommissionRate = 0.0;
            double house = App.TotalPrice;
            double commisssiondouable = Convert.ToDouble(txtCommission.Text);
            CommissionRate = (house * commisssiondouable) / 100;
            txtAgentCommissionandhouseprice.Text = CommissionRate.ToString();
        }
        private void LoadPivotThemes()
        {
            LayoutRoot.Background = Custom.getPivotBackground();

        }
        private void imgTitle_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
        {

        }

        private void REg_ValueChanged_1(object sender, DateTimeValueChangedEventArgs e)
        {
            try
            {
                DateTime date = (DateTime)e.NewDateTime;
                this.REg.Value = date;
                App.Todate = REg.ValueString;
            }
            catch (Exception ex)
            {
            }
        }

        private void AppBarSaveData_Click(object sender, EventArgs e)
        {
            if (Appsettings.RegstrationDate != REg.Value.ToString())
            {
                Appsettings.TotalSumForSalesPrice = 0;
                Appsettings.CompareMonth = 0;
            }
            Appsettings.RegstrationDate = REg.Value.ToString();
           

            NavigationService.Navigate(new Uri("/Views/Result/ResultPage.xaml?sectionId=7&RD=" + REg.Value + "&ACH=" + txtAgentCommissionandhouseprice.Text + "&TP=" + txtTotalPrice.Text + "&AC=" + txtCommission.Text, UriKind.Relative));
        }

        private void txtCommission_MouseLeave_1(object sender, System.Windows.Input.MouseEventArgs e)
        {
            double CommissionRate = 0.0;
            double house = App.TotalPrice;
            double commisssiondouable = Convert.ToDouble(txtCommission.Text);
            CommissionRate = (house * commisssiondouable) / 100;
            txtAgentCommissionandhouseprice.Text = CommissionRate.ToString();
          

        }
    }
} 